
package net.atremmedia.gwt.actionjava.examples.bounds.samples.curve;

import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Shape;
import actionjava.geom.shape.Rectangle2D;
import com.allen_sauer.gwt.log.client.Log;

public abstract class DrawCurveBounds extends AbstractBounds
{
	private Shape curveShape;
	private Graphics curveGraphics;
	private Rectangle2D curveBounds = null;

	/*
	 * ---------------------------------------------------------------
	 *	Constructor
	 * ---------------------------------------------------------------
	 */

	public DrawCurveBounds(String name, String description, String exampleSrc, AJExampleOverview base)
	{
		super(name, description, exampleSrc, base);
	}

	/*
	 * ---------------------------------------------------------------
	 *	Public methods
	 * ---------------------------------------------------------------
	 */

	public void run(boolean drawBounds)
	{
		setCurveShape(new Shape());

		if(drawBounds) {
			setBounds();
			drawDots(getCurveGraphics());
			drawControlPointLines(getCurveGraphics());

			drawBounds(getBounds(), getCurveGraphics());
			logBounds(getBounds());
		}

		drawLegenda();
	}

	public void drawDot(double x, double y, String color, Graphics graph)
	{
		graph.beginStroke(color).beginFill(color).drawCircle(x, y, 5).endStroke().endFill();
	}

	public void drawBounds(Rectangle2D bounds, Graphics graph)
	{
		graph.beginStroke(BOUNDS_LINE_COLOR).drawRect(bounds.x, bounds.y, bounds.width, bounds.height).endStroke();
	}

	public void logBounds(Rectangle2D bounds)
	{
		double x = Math.round(bounds.x);
		double y = Math.round(bounds.y);
		double w = Math.round(bounds.width);
		double h = Math.round(bounds.height);

		Log.info("X: " + x);
		Log.info("Y: " + y);
		Log.info("WIDTH: " + w);
		Log.info("HEIGHT: " + h);

		Log.warn("x: " + x + " y: " + y + " w: " + w + " h: " + h);
	}

	/*
	 * ---------------------------------------------------------------
	 *	to be overriden methods
	 * ---------------------------------------------------------------
	 */

	public void drawControlPointLines(Graphics graph)
	{
	}

	public void drawDots(Graphics graph)
	{
	}

	@Override
	public void setBounds()
	{
	}

	/*
	 * ---------------------------------------------------------------
	 *	Getters & Setters
	 * ---------------------------------------------------------------
	 */

	public Shape getCurveShape()
	{
		return curveShape;
	}

	public void setCurveShape(Shape curveShape)
	{
		this.curveShape = curveShape;
		this.curveGraphics = curveShape.getGraphics();
	}

	public Graphics getCurveGraphics()
	{
		return curveGraphics;
	}

	public Rectangle2D getBounds()
	{
		return curveBounds;
	}

	public void setBounds(Rectangle2D bounds)
	{
		this.curveBounds = bounds;
	}
}
